﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using EZCRS.HCMS.Bll.AIR;
using EZCRS.HCMS.Entity;
using System.Collections.Generic;
using EZCRS.HCMS.Bll.Report;

using dotnetCHARTING;
using System.Drawing;

namespace EZCRS.HCMS.report
{
    public partial class channel_lr : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }

        private void InitPage()
        {
            int iYear1 = DateTime.Now.Year - 5;

            for (int i = iYear1; i <= DateTime.Now.Year; i++)
            {
                ddlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            ddlYear.SelectedIndex = ddlYear.Items.Count - 1;

            EZCRS.HCMS.Bll.AIR.TAChannel channel = new TAChannel();

            List<Channel> lst = channel.GetAll();

            foreach (Channel cl in lst)
            {
                ddlChannel.Items.Add(new ListItem(cl.Name, cl.Name));
            }

            ddlChannel.Items.Insert(0, new ListItem("==All==", string.Empty));

        }

        protected void btnShow_Click(object sender, EventArgs e)
        {
            ShowReport(Convert.ToInt32(ddlYear.SelectedValue),int.Parse(ddlMonth.SelectedValue), ddlChannel.SelectedValue);
        }


        private void ShowReport(int Year, int Month, string Channel)
        {

            SeriesCollection sc = new SeriesCollection();

            chrReport.Title = "预订产量环比图";

            chrReport.YAxis.Scale = Scale.Normal;

            

            chrReport.YAxis.Label.Text = "房间数";

            chrReport.TempDirectory = "../temp";

            chrReport.Width = 700;
            chrReport.Height = 400;

            ReservationReport report = ReservationReport.getInstance();

            Series ser = new Series();
            ser.Name = Channel;

            if (string.IsNullOrEmpty(Channel))
                chrReport.XAxis.Label.Text = "所有渠道";
            else
                chrReport.XAxis.Label.Text = Channel;

            ser.Name = chrReport.XAxis.Label.Text;

            if (Month > 0)
            {

                for (int i = 2; i >= 0; i--)
                {
                    int iMonth2 = Month - i;
                    int iYear2 = Year;

                    if (iMonth2 <= 0)
                    {
                        iMonth2 += 12;
                        iYear2 -= 1;
                    }

                    int iChannelAmount = report.GetReserveMonthAmountByChannel(iYear2, iMonth2, Channel);

                    Element el = new Element();

                    el.Name = iYear2.ToString() + "年" + iMonth2.ToString() + "月";

                    el.YValue = iChannelAmount;

                    el.ShowValue = true;

                    ser.Elements.Add(el);

                }
            }
            else
            {


                //年度
                for (int i = 2; i >= 0; i--)
                {
                    int iYear2 = Year - i;

                    int iChannelAmount = report.GetReserveYearAmountByChannel(iYear2, Channel);

                    Element el = new Element();

                    el.Name = iYear2.ToString() + "年";

                    el.YValue = iChannelAmount;

                    el.ShowValue = true;

                    ser.Elements.Add(el);

                }

            }

            sc.Add(ser);

            sc[0].DefaultElement.Color = Color.FromArgb(100, 255, 200);
            sc[0].Type = SeriesType.Column;

            chrReport.SeriesCollection.Add(sc);

        }
    }
}
